package edu.aynu.util;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用的返回类
 * @author haha
 */
public class Result {

    /**
     * 100 通用成功
     * 200 通用失败
     * 400 参数错误
     */
    private int code;

    private String msg;

    private Map<String,Object> data = new HashMap<String,Object>();

    public static Result success(){
        Result result = new Result();
        result.setCode(100);
        result.setMsg("处理成功");
        return result;
    }
    public static Result fail(){
        Result result = new Result();
        result.setCode(200);
        result.setMsg("处理失败");
        return result;
    }

    public static Result fail(String code){
        Result result = new Result();
        result.setCode(200);
        result.setMsg(code);
        return result;
    }

    public Result add(String key,Object value){
        this.getData().put(key,value);
        return this;
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> extend) {
        this.data = extend;
    }
}
